package com.elseyu.osctest.osc;

import android.util.Log;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by Administrator on 2016/9/9.
 */
public class ApiConnector {
    private static final String TAG = "ApiConnector";
    public String getAccessToken() {
        OkHttpUtils
                .get()
                .url(OSCParams.API_URL)
                .addParams("client_id", "GC6NJbw5UilfBdhuidSp")
                .addParams("client_secret", "Jg9bqXfzyPyIl6cDo6auIPCf2O6jLyKy")
                .addParams("grant_type", "refresh_token")
                .addParams("redirect_uri", "aa")
//                .addParams("code", "P0Ccvv")
                .addParams("refresh_token", "0c32d696-cc89-4f94-be86-31b447548960")
                .addParams("dataType", "json")
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {

                    }
                });
        return null;
    }
    public String getTweetList() {
        Response res = null;
        try {
            res = OkHttpUtils
                    .get()
                    .url(OSCParams.API_URL)
                    .build()
                    .execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (res != null) {
            try {
                return res.body().string();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public String getTweetList(int index, int size) {
        Response res = null;
        try {
            res = OkHttpUtils
                    .get()
                    .url(OSCParams.TWEET_LIST_API)
                    .addParams("access_token","bad273b3-c6d2-4a08-9781-d487ff6fce8b")
                    .addParams("pageSize","" + size)
                    .addParams("pageIndex","" + index)
                    .addParams("dataType","json")
                    .build()
                    .execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (res != null) {
            try {
                String json = res.body().string();
                Log.d(TAG, "getTweetList: " + json);
                return json;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }


}
